<%@ page language="java" contentType="text/html; charset=GBK"  
    pageEncoding="GBK"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=GBK">  
<title>Compose Message</title>  
<style type="text/css">  
body{   
 color : #000 ;   
 font-size : 12px ;   
  
 margin : 0px auto ;   
 }   
</style>
<script type="text/javascript">
function validate_composeMessage_form() {
	
	// Check if neither is selected
	if (document.getElementById("public").checked == false && document.getElementById("private").checked == false) {
		alert ("Please select either a public or private message.");
		return false;
	}
	
	// Check if public that poll(s) selected
	if (document.getElementById("public").checked == true && document.getElementById("poll_list").selectedIndex < 1) {
		alert ("Please select one or more polls from drop down menu.");
		return false;
	}
	//alert ("validate_composeMessage_form() run");
	// Check if private that user(s) selected
//	if (document.getElementById("private").checked == true && document.getElementById("pollUser_List").selectedIndex < 1) {
//		alert ("Please select one or more users from drop down menu.");
//		return false;
//	}
	
	// Check if message text empty
	if (document.getElementById("composeMessage_text").value == "") {
		alert ("Please insert message text.");
		return false;
	}

	// Otherwise good to go
	
	return true;
}

function display_polls_list() {
	// Send ajax to fill it in?
	//alert("display_polls_list() run");
	document.getElementById("pollUser_list").style.visibility = "hidden";
	document.getElementById("pollUser_list_label").style.visibility = "hidden";
	document.getElementById("poll_list").style.visibility = "visible";
	document.getElementById("poll_list_label").style.visibility = "visible";
}

function display_users_list() {
	// Send ajax to fill it in?	
	//alert("display_users_list() run");
	document.getElementById("poll_list").style.visibility = "hidden";
	document.getElementById("poll_list_label").style.visibility = "hidden";
	document.getElementById("pollUser_list").style.visibility = "visible";
	document.getElementById("pollUser_list_label").style.visibility = "visible";
}

function generate_polls_list() {
	// Ajax to generate 
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
	} else {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	// What to do when changed?
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			// What to do with stuff received??
			
			
		}
	}
	
	//xmlhttp.open("GET","signupAJAX.php?u=" + document.getElementById('username').value + "&t=" + document.getElementById('title').value + "&x=" + document.getElementById('firstname').value + "&z=" + document.getElementById('surname').value + "&a=" + document.getElementById('address').value + "&c=" + document.getElementById('credit').value + "&p=" + document.getElementById('pw1').value + "&q=" + document.getElementById('pw2').value );
	xmlhttp.open("GET","generatePollList?pm=" + "pm", true);
	xmlhttp.send();
	return;
}

</script>  
</head>  


<body>

<p>This compose Message form needs to be put in the Poll Master User template</p>

<form action="sendMessageServlet" method="post" name="composeMessage" onsubmit="return validate_composeMessage_form();">
<table border="1">
<tr>
	<td colspan="2" align="center" bgcolor="silver">COMPOSE MESSAGE</td>
</tr>
<tr>
	<td><input type="radio" name="privacy" id="public" value="public" onclick="display_polls_list()"><label for="public">Public</label></td>
	<td><label id="poll_list_label" style="visibility:hidden;">Send to...   </label>
		<select name="poll_list" id="poll_list" style="visibility:hidden;">
		<option>Please select poll(s)</option>
		<option>Dummy option</option>
		<option>Dummy option two</option>
		<!--  JSP query and while loop -->
		</select>
	</td>
</tr>
<tr>
	<td><input type="radio" name="privacy" id="private" value="private"onclick="display_users_list()"><label for="private" >Private</label></td>
	<td><label id="pollUser_list_label" style="visibility:hidden;">Send to...   </label>
		<select name="pollUser_list" id="pollUser_list" style="visibility:hidden;">
		<option>Please select user(s)</option>
		<option>Dummy option</option>
		<option>Dummy option two</option>
		<!--  JSP query and while loop -->
		</select>
	</td>
</tr>
<tr>
	<td colspan="2" width="100"><textarea id="composeMessage_text" rows="5" cols="100" style="resize: none;"></textarea></td>
</tr>

<tr>
	<td colspan="2"><input type="submit" value="SEND"/></td>
</tr>
</table>
</form>

</body>  
</html>  
